using IM.Easy.Infrastructure.Query;
using Microsoft.AspNetCore.Mvc;
using IM.Easy.SystemServices.Dtos;
using IM.Easy.SystemServices.IServices;
using IM.Easy.Entity.System;
using IM.Easy.Core.Attributes;
using Mapster;
using IM.Easy.Core.AppContext;

namespace IM.Easy.Api.Controllers.System
{
    /// <summary>
    /// ShortcutController 控制器
    /// </summary>
    [Route("system/shortcut")]
    public class ShortcutController : ControllerBase
    {
        private readonly IShortcutService _service;

        /// <summary>
        /// 构造函数，注入服务
        /// </summary>
        /// <param name="service">服务接口</param>
        public ShortcutController(IShortcutService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取所有Shortcut对象
        /// </summary>
        /// <returns>返回Shortcut列表</returns>
        [HttpGet]
        [Api(Name = "获取我的快捷功能")]
        public List<ShortcutDto> GetList()
        {
            var uid = ImApp.User.Id;
            var shortcuts = _service.GetUserShortcuts(uid);
            var response = shortcuts.Adapt<List<ShortcutDto>>();
            return response;
        }

        /// <summary>
        /// 创建新的Shortcut对象
        /// </summary>
        /// <param name="dto">要创建的Shortcut对象</param>
        /// <returns>返回创建后的Shortcut对象</returns>
        [HttpPost]
        [Api(Name = "添加快捷功能")]
        public Shortcut Create([FromBody] ShortcutDto dto)
        {
            var entity = dto.Adapt<Shortcut>();
            entity.Owner = ImApp.User.Id;
            _service.Create(entity);
            return entity; // 直接返回创建的实体
        }

        /// <summary>
        /// 批量删除Shortcut对象
        /// </summary>
        /// <param name="ids">对象的IDS</param>
        [HttpDelete]
        [Api(Name = "删除快捷功能")]
        public void Delete([FromBody] params long[] ids)
        {
            _service.Delete(ids);
        }

    }
}
